const app = getApp()
const $api = require('../../../utils/api.js').API;
Page({
    data: {
        list:{},
        role:0
    },
    onLoad: function() {
        this.setData({
            'role':wx.getStorageSync('role')
        })
        wx.showLoading()
        this.getList();
    },
    getList:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('delivery/list',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.hideLoading()
                that.setData({
                    list:res.data.data
                })
            }
        })
    },
    delDelivery:function(e){
        var id = e.target.dataset.id
        var that = this
        var data ={'id':id}
        $api.delete('delivery/delete',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showLoading()
                that.getList();
                wx.showToast({
                    title:'删除成功!!',
                    duration:3000,
                    mask:true, 
                    icon:'none',
                })
            }
        }).catch(err => {
            //请求失败
            //console.log('error',err);
        })
    },
    toCompany:function(e){
        var id = e.target.dataset.uid
        if(wx.getStorageSync('role') == 2){
            //个人直接直接跳转聊天
            wx.navigateTo({
                url: '/pages/message/online/toCompany?touid='+id
            })
            return;
        }
        var that = this
        var data = {
            'company_uid':wx.getStorageSync('uid'),
            'uid':id
         }
        $api.get('vip/is_buy',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.navigateTo({
                    url: '/pages/message/online/toCompany?touid='+id
                })
            }else{
                wx.showToast({
                    title:'VIP已过期',
                    duration:3000,
                    mask:true,
                    icon:'none',
                    success:function(){
                        setTimeout(function(){
                            wx.navigateTo({
                                url: '/pages/vip/index'
                            })
                        },3000) //延迟时间 这里是
                    }
                })
            }
        })
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
      }
});